package com.itcncp.wechat.app.mini.controller;
import com.itcncp.common.base.BaseController;
import com.itcncp.common.model.OrderCodeType;
import com.itcncp.common.rongCloud.models.SdkHttpResult;
import com.itcncp.common.rongCloud.models.SdkHttpResultToken;
import com.itcncp.common.util.*;
import com.itcncp.wechat.app.common.constant.ApiConstant;
import com.itcncp.wechat.app.common.constant.ApiResult;
import com.itcncp.wechat.app.common.constant.ApiResultConstant;
import com.itcncp.wechat.app.dao.model.*;
import com.itcncp.wechat.app.rpc.api.*;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
/**
 *
 * Created by shuitcncp on 2016/12/10.
 */
@Controller
@RequestMapping("/user")
@Api(tags = "用户基础信息表",value = "用户信息", description = "用户的基本信息接口",
        produces = "produces",consumes = "consumes",basePath = "/user")

public class UserController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserCustomerInfoService userCustomerInfoService;
    @Autowired
    private UserVerifyJnlService userVerifyJnlService;
    @Autowired
    private ItcsFeedbackJnlService itcsFeedbackJnlService;
    @Autowired
    private ItcsNoticeJnlService itcsNoticeJnlService;
    @Autowired
    private ItcsCityInfoService itcsCityInfoService;
    @Autowired
    private ItcsCityLimitInfoService itcsCityLimitInfoService;

    @ResponseBody
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(value="手机号与密码进行登录",notes="用户已注册，并在微信微程序登录中，此时在另一个微信打开小程序，可调用此接口")
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号", defaultValue = ""),
            @ApiImplicitParam(paramType = "query", name = "password", dataType = "String", required = true, value = "密码"),
            @ApiImplicitParam(paramType = "query", name = "openid", dataType = "String", required = true, value = "小程序授权openid"),
            @ApiImplicitParam(paramType = "query", name = "lon", dataType = "Double", required = false, value = "经度"),
            @ApiImplicitParam(paramType = "query", name = "lat", dataType = "Double", required = false, value = "纬度")
    })
    public Object login(HttpServletRequest request,
                        @RequestParam(required = true,defaultValue = "",value = "mobile") String mobile,
                        @RequestParam(required = true,defaultValue = "",value = "password") String password,
                        @RequestParam(required = true,defaultValue = "",value = "openid") String openid,
                        @RequestParam(required = false,defaultValue = "",value = "lat") Double lon,
                        @RequestParam(required = false,defaultValue = "",value = "lon") Double lat) {

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_ACCOUNT_PASS_ERROR);
        }

        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_ACCOUNT_PASS_ERROR);
        }

        //验证密码是否为空
        if(StringUtils.isEmpty( password)){
            return new ApiResult( ApiResultConstant.APP_ACCOUNT_PASS_ERROR);
        }

        //验证设备号是否为空
        if(StringUtils.isEmpty( openid)){
            return new ApiResult( ApiResultConstant.APP_OPENID_EXPIRED);
        }

        UserCustomerInfo userInfo = new UserCustomerInfo();
        userInfo.setMobile( mobile );
        userInfo.setPassword( password );
        userInfo.setDeviceAppNo( openid );
        userInfo.setLoginMode(new Byte("2"));

        if(null != lat && null != lon){
            userInfo.setLatitude( lat );
            userInfo.setLongitude( lon );
        }

        userInfo = userCustomerInfoService.login( userInfo );

        if(null != userInfo){
            return  new ApiResult( ApiResultConstant.SUCCESS,userInfo );
        }

        return new ApiResult( ApiResultConstant.APP_ACCOUNT_PASS_ERROR);
    }



    /**
     * 登录小程序
     * @param request
     * @param openid
     * @param lon
     * @param lat
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/loginWxMini", method = RequestMethod.POST)
    @ApiOperation(value="微信openId登录",notes="用户已注册登录，下次打开后直接调用此接口，通过openid进行登录！")
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "openid", dataType = "String", required = true, value = "小程序授权openid"),
            @ApiImplicitParam(paramType = "query", name = "lon", dataType = "Double", required = false, value = "经度"),
            @ApiImplicitParam(paramType = "query", name = "lat", dataType = "Double", required = false, value = "纬度")
    })
    public Object loginWxMini(HttpServletRequest request,
                        @RequestParam(required = true,defaultValue = "",value = "openid") String openid,
                        @RequestParam(required = false,defaultValue = "",value = "lat") Double lon,
                        @RequestParam(required = false,defaultValue = "",value = "lon") Double lat) {

        //验证设备号是否为空
        if(StringUtils.isEmpty( openid)){
            return new ApiResult( ApiResultConstant.APP_OPENID_EXPIRED);
        }
        UserCustomerInfo userInfo = new UserCustomerInfo();
        userInfo.setDeviceAppNo( openid );
        userInfo.setLoginMode(new Byte("2"));
        if(null != lat){
            userInfo.setLatitude( lat );
            userInfo.setLongitude( lon );
        }

        userInfo = userCustomerInfoService.loginWxMini( userInfo );

        if(null != userInfo){
            return  new ApiResult( ApiResultConstant.SUCCESS,userInfo );
        }

        return new ApiResult( ApiResultConstant.APP_TOKEN_LOGIN_EXPIRED);
    }


    /**
     * 退出登录
     * @param request
     * @param userId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    @ApiOperation(value="退出登录",notes="退出登录，当用户退出时调用此接口！")
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID")
    })
    public Object logout(HttpServletRequest request,
                         @RequestParam(required = true,defaultValue = "",value = "userId") Long userId) {

        //验证用户userId
        if(userId<=0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL);
        }

        UserCustomerInfo userInfo = new UserCustomerInfo();
        userInfo.setUserId(userId);
        userInfo.setDeviceAppNo("");
        Integer result = userCustomerInfoService.updateByPrimaryKeySelective(userInfo);

        if(result > 0){
            return  new ApiResult( ApiResultConstant.SUCCESS);
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }



    @ResponseBody
    @RequestMapping(value = "/getById", method = RequestMethod.POST)
    @ApiOperation(value="获取用户个人信息",notes=" ")
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID")
    })
    public Object getById(
            @RequestParam(required = true,defaultValue = "0",value = "userId") Long userId) {

        //验证用户userId
        if(userId<=0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL);
        }

        UserCustomerInfo userInfo = userCustomerInfoService.selectByPrimaryKey( userId );

        return new ApiResult( ApiResultConstant.SUCCESS,userInfo);
    }


    @ResponseBody
    @RequestMapping(value = "/updateHead", method = RequestMethod.POST)
    @ApiOperation(value="更新用户头像",notes=" ")
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID"),
            @ApiImplicitParam(paramType = "query", name = "head", dataType = "String", required = true, value = "头像图片路径 \n 需先调用图片上传接口")
    })
    public Object updateHead(
            @RequestParam(required = true,defaultValue = "0",value = "userId") Long userId,
            @RequestParam(required = true,defaultValue = "",value = "head") String head) {

        //验证用户userId
        if(userId<=0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL);
        }


        //验证用户昵称
        if(StringUtils.isEmpty( head )){
            return new ApiResult( ApiResultConstant.APP_NOT_NAME);
        }

        UserCustomerInfo userInfo  = new UserCustomerInfo();
        userInfo.setUserId( userId );
        userInfo.setHead( head );
        userInfo.setUpdateTime( new Date(  ) );

        Integer result = userCustomerInfoService.updateByPrimaryKeySelective( userInfo );

        if(result>0){
            return new ApiResult( ApiResultConstant.SUCCESS);
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }


    @ResponseBody
    @ApiOperation(value="更新用户昵称",notes=" ")
    @RequestMapping(value = "/updateNickname", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID"),
            @ApiImplicitParam(paramType = "query", name = "nickname", dataType = "String", required = true, value = "昵称")
    })
    public Object updateNickname(
            @RequestParam(required = true,defaultValue = "0",value = "userId") Long userId,
            @RequestParam(required = true,defaultValue = "",value = "nickname") String nickname) {

        //验证用户userId
        if(userId<=0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL);
        }


        //验证用户昵称
        if(StringUtils.isEmpty( nickname )){
            return new ApiResult( ApiResultConstant.APP_NOT_NAME);
        }

        UserCustomerInfo userInfo  = new UserCustomerInfo();
        userInfo.setUserId( userId );
        userInfo.setNickname( nickname );
        userInfo.setUpdateTime( new Date(  ) );

        Integer result = userCustomerInfoService.updateByPrimaryKeySelective(userInfo);

        if(result>0){
            return new ApiResult( ApiResultConstant.SUCCESS);
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }


    @ResponseBody
    @ApiOperation(value="是否自动扣款",notes="扣款方式 1非自动扣款 2自动扣款（不需要密码）")
    @RequestMapping(value = "/isPayMethod", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID"),
            @ApiImplicitParam(paramType = "query", name = "payMethod", dataType = "Integer", required = true, value = "扣款方式 1非自动扣款 2自动扣款（不需要密码）")
    })
    public Object isPayMethod(
            @RequestParam(required = true,defaultValue = "0",value = "userId") Long userId,
            @RequestParam(required = true,defaultValue = "",value = "payMethod") Integer payMethod) {

        //验证用户userId
        if(userId<=0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL);
        }


        //验证用户昵称
        if(payMethod!=1){
            payMethod = 2;
        }

        UserCustomerInfo userInfo  = new UserCustomerInfo();
        userInfo.setUserId( userId );
        userInfo.setPayMethod(payMethod.byteValue());
        userInfo.setUpdateTime( new Date(  ) );

        Integer result = userCustomerInfoService.updateByPrimaryKeySelective( userInfo );

        if(result>0){
            return new ApiResult( ApiResultConstant.SUCCESS);
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }


    @ResponseBody
    @ApiOperation(value="更新用户地址",notes=" ")
    @RequestMapping(value = "/updateAddress", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID"),
            @ApiImplicitParam(paramType = "query", name = "address", dataType = "String", required = true, value = "地址")
    })
    public Object updateAddress(
            @RequestParam(required = true,defaultValue = "0",value = "userId") Long userId,
            @RequestParam(required = true,defaultValue = "",value = "address") String address) {

        //验证用户userId
        if(userId<=0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL);
        }


        //验证用户地址
        if(StringUtils.isEmpty( address )){
            return new ApiResult( ApiResultConstant.APP_PARAM_ERROR);
        }

        UserCustomerInfo userInfo  = new UserCustomerInfo();
        userInfo.setUserId( userId );
        userInfo.setAgentAddress( address );
        userInfo.setUpdateTime( new Date(  ) );

        Integer result = userCustomerInfoService.updateByPrimaryKeySelective( userInfo );

        if(result>0){
            return new ApiResult( ApiResultConstant.SUCCESS);
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }


    @ResponseBody
    @ApiOperation(value="ITC注册",notes="如果用户在其他平台已注册会提示用户该账户已注册!\n可调用login接口进行登录!")
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号", defaultValue = ""),
            @ApiImplicitParam(paramType = "query", name = "password", dataType = "String", required = true, value = "密码"),
            @ApiImplicitParam(paramType = "query", name = "security", dataType = "String", required = true, value = "安全码"),
            @ApiImplicitParam(paramType = "query", name = "openid", dataType = "String", required = true, value = "小程序授权openid"),
            @ApiImplicitParam(paramType = "query", name = "lon", dataType = "Double", required = false, value = "经度"),
            @ApiImplicitParam(paramType = "query", name = "lat", dataType = "Double", required = false, value = "纬度")
    })
    public Object register(HttpServletRequest request,
                         @RequestParam(required = true,defaultValue = "",value = "mobile") String mobile,
                         @RequestParam(required = true,defaultValue = "",value = "password") String password,
                           @RequestParam(required = true,defaultValue = "",value = "security") String security,
                         @RequestParam(required = true,defaultValue = "",value = "openid") String openid,
                         @RequestParam(required = false,defaultValue = "0",value = "lon") Double lon,
                         @RequestParam(required = false,defaultValue = "0",value = "lat") Double lat ) {

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }
        //验证手机格式
        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        //验证密码是否为空
        if(StringUtils.isEmpty( password )){
            return new ApiResult( ApiResultConstant.APP_PARAM_ERROR);
        }

        //验证安全码
        if(StringUtils.isEmpty( security )){
            return new ApiResult( ApiResultConstant.APP_SECURITY_ERROR);
        }

        //验证微信授权码
        if(StringUtils.isEmpty( openid )){
            return new ApiResult( ApiResultConstant.APP_OPENID_EXPIRED);
        }

//        /**
//         * 验证码类型
//         * 1.用户注册验证码
//         * 2.登录确认验证码
//         * 3.修改密码验证码
//         * 4.身份验证验证码
//         * 5.信息变更验证码
//         * 6.活动确认验证码
//         */
//        UserVerifyJnl itemCode = userVerifyJnlService.verifyRegisterCode(mobile,registerCode,1);
//
//        if(null == itemCode){
//            return new ApiResult( ApiResultConstant.APP_SMS_ERROR);
//        }


        UserCustomerInfo userInfo =  new UserCustomerInfo();
        userInfo.setMobile( mobile );
        userInfo.setSecurity( security );
        userInfo.setDeviceAppNo( openid );
        userInfo.setPassword( password );
        userInfo.setLoginMode(new Byte("2"));
        if(null != lat && null != lon) {
            userInfo.setLongitude( lon );
            userInfo.setLatitude( lat );
        }

        userInfo = userCustomerInfoService.registerInfo(userInfo);

        if(null != userInfo){
            return new ApiResult( ApiResultConstant.SUCCESS,userInfo);
        }

        return  new ApiResult( ApiResultConstant.APP_ACCOUNT_EXISTS );
    }



    /**
     * 修改密码
     * @return
     */
    @ResponseBody
    @ApiOperation(value="修改密码/重置密码",notes="重置密码，修改密码共用该接口!")
    @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号码"),
            @ApiImplicitParam(paramType = "query", name = "password", dataType = "String", required = true, value = "新密码"),
            @ApiImplicitParam(paramType = "query", name = "openid", dataType = "String", required = true, value = "微信openid，必须授权openid方可修改密码"),
            @ApiImplicitParam(paramType = "query", name = "security", dataType = "String", required = true, value = "安全码"),
            @ApiImplicitParam(paramType = "query", name = "registerCode", dataType = "String", required = true, value = "短信码")
    })
    public  Object updatePwd(HttpServletRequest request,
                            @RequestParam(required = true,defaultValue = "",value = "mobile") String mobile,
                            @RequestParam(required = true,defaultValue = "",value = "password") String password,
                            @RequestParam(required = true,defaultValue = "",value = "openid") String openid,
                            @RequestParam(required = true,defaultValue = "",value = "security") String security,
                            @RequestParam(required = true,defaultValue = "",value = "registerCode") String registerCode){

        //验证设备号是否为空
        if(StringUtils.isEmpty( openid )){
            return new ApiResult( ApiResultConstant.APP_OPENID_EXPIRED);
        }

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        if(!IDCardUtil.mobile(  mobile)){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        //密码是否为空
        if(StringUtils.isEmpty( password )){
            return new ApiResult( ApiResultConstant.APP_PASSWORD_TRIM);
        }

        //安全验证密码是否为空
        if(StringUtils.isEmpty( security )){
            return new ApiResult( ApiResultConstant.APP_SECURITY_ERROR );
        }

        //验证密码是否为空
        if(StringUtils.isEmpty( registerCode )){
            return new ApiResult( ApiResultConstant.APP_SMS_ERROR );
        }

        UserCustomerInfoExample userCustomerInfoExample = new UserCustomerInfoExample();
        userCustomerInfoExample.createCriteria().andMobileEqualTo(mobile);
        UserCustomerInfo userInfo = userCustomerInfoService.selectFirstByExample(  userCustomerInfoExample );

        if(null == userInfo){
            return  new ApiResult( ApiResultConstant.APP_ACCOUNT_NOT_EXISTS );
        }

        if(userInfo.getStatus()!=1){
            return  new ApiResult( ApiResultConstant.APP_ACCOUNT_LOCK);
        }

        //安全验证密码是否正确
        if(!userInfo.getSecurity().equals( AESUtil.encryptPassword( security ) )){
            return new ApiResult( ApiResultConstant.APP_SECURITY_ERROR );
        }

        /**
         * 验证码类型
         * 1.用户注册验证码
         * 2.登录确认验证码
         * 3.修改密码验证码
         * 4.身份验证验证码
         * 5.信息变更验证码
         * 6.活动确认验证码
         */
        UserVerifyJnl userVerifyCode = userVerifyJnlService.verifyRegisterCode( mobile,registerCode,3);

        if(null == userVerifyCode){
            return new ApiResult(ApiResultConstant.APP_SMS_ERROR);
        }

        // 逻辑处理
        userInfo.setPassword(AESUtil.encryptPassword( password ));

        Integer total =  userCustomerInfoService.updateByPrimaryKeySelective( userInfo );

        if(total>0){
            return new ApiResult( ApiResultConstant.SUCCESS);
        }

        return  new ApiResult( ApiResultConstant.FAILED );

    }
    /**
     * 反馈
     * @return
     */
    @ResponseBody
    @ApiOperation(value="微信小程序反馈",notes="联系方式,如用户不输入则传用户的登录手机号!")
    @RequestMapping(value = "/addFeedback", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "Long", required = true, value = "用户ID"),
            @ApiImplicitParam(paramType = "query", name = "content", dataType = "String", required = true, value = "反馈内容"),
            @ApiImplicitParam(paramType = "query", name = "contact", dataType = "String", required = true, value = "联系方式,如用户不输入则传用户的登录手机号")
    })
    public Object addFeedback(HttpServletRequest request,
                              @RequestParam(required = true,defaultValue = "0",value = "")Long userId,
                              @RequestParam(required = true,defaultValue = "",value = "")String content,
                              @RequestParam(required = true,defaultValue = "",value = "")String contact){

        if(userId <= 0){
            return new ApiResult( ApiResultConstant.APP_ILLEGAL );
        }

        ItcsFeedbackJnl feedback = new ItcsFeedbackJnl();
        feedback.setUserId( userId );
        feedback.setParentFeedbackId( new Long("0") );
        feedback.setChannel( new Byte( "5" ) );
        feedback.setContact( contact );
        feedback.setType( new Byte( "0" ) );
        feedback.setContent( content );
        feedback.setCreateTime( new Date(  ) );
        feedback.setFeedbackId( OrderUtils.createOrderId( OrderCodeType.FEEDBACK_ID ) );

        Integer total = itcsFeedbackJnlService.insertSelective( feedback );

        if(total>0){
            return  new ApiResult( ApiResultConstant.SUCCESS );
        }

        return new ApiResult( ApiResultConstant.FAILED );
    }

    /**
     * 系统通知
     * @return
     */
    @ResponseBody
    @ApiResponse(code=200,message = "系统通知",response = ItcsNoticeJnl.class)
    @ApiOperation(value="系统通知",notes="该通知属于永久性，除非平台删除！与微信推送不同！\n类似于新闻，最新信息也可通过微信直接推送给小程序！")
    @RequestMapping(value = "/findByNotice", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "Integer",
                    required = true,defaultValue = "1", value = "每页条数"),
            @ApiImplicitParam(paramType = "query", name = "pageIndex", dataType = "Integer",
                    required = true,defaultValue = "5",  value = "第几页"),
            @ApiImplicitParam(paramType = "query", name = "search", dataType = "String", required = false, value = "关键字查询")
    })
    public Object findByNotice(HttpServletRequest request,
                               @RequestParam(required = false, defaultValue = "0", value = "pageSize") Integer pageSize,
                               @RequestParam(required = false, defaultValue = "5", value = "pageIndex") Integer pageIndex,
                               @RequestParam(required = false, defaultValue = "", value = "search") String search){

        ItcsNoticeJnlExample noticeExample = new ItcsNoticeJnlExample();
        //模糊查询
        if(StringUtils.isNotEmpty( search )) {
            noticeExample.or().andTitleLike( "%"+search+"%" )
                    .andSummaryLike( "%"+search+"%" )
                    .andContentLike( "%"+search+"%" );
        }

        //分页查询
        List<ItcsNoticeJnl> notices = itcsNoticeJnlService.selectByExampleForStartPage(noticeExample, pageSize, pageIndex);


        return new ApiResult( ApiResultConstant.SUCCESS,notices );
    }


    @ResponseBody
    @ApiResponse(code=200,message = "通知详情",response = ItcsNoticeJnl.class)
    @RequestMapping(value = "/getByNotice", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "noticeId", dataType = "Long", required = true, value = "通知ID")
    })
    public Object getByNotice(HttpServletRequest request,
                         @RequestParam(required = false, defaultValue = "0", value = "noticeId") Long noticeId){

        ItcsNoticeJnl notice = itcsNoticeJnlService.selectByPrimaryKey( noticeId );

        //查询一条推送信息
        return new ApiResult( ApiResultConstant.SUCCESS, notice);
    }

    /**
     * 验证短信码
     * @return
     */
    @ResponseBody
    @ApiOperation(value="验证注册短信码",notes="如注册信息与验证码不在同一页面时，可先调用此接口先验证!")
    @RequestMapping(value = "/verifyRegisterCode", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号"),
            @ApiImplicitParam(paramType = "query", name = "registerCode", dataType = "String", required = true, value = "验证码")
    })
    public  Object verifyRegisterCode(
            HttpServletRequest request,
            @RequestParam(value = "mobile",defaultValue = "") String mobile,
            @RequestParam(value = "registerCode",defaultValue = "") String registerCode){

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        //验证密码是否为空
        if(StringUtils.isEmpty( registerCode )){
            return new ApiResult( ApiResultConstant.APP_SMS_ERROR);
        }

        /**
         * 验证码类型
         * 1.用户注册验证码
         * 2.登录确认验证码
         * 3.修改密码验证码
         * 4.身份验证验证码
         * 5.信息变更验证码
         * 6.活动确认验证码
         */
        UserVerifyJnl itemCode = userVerifyJnlService.verifyRegisterCode(mobile,registerCode,1);

        if(null != itemCode){
            return new ApiResult( ApiResultConstant.SUCCESS);
        }

        return  new ApiResult( ApiResultConstant.APP_SMS_EXPIRED );
    }

    /**
     *  获取注册短信验证码
     */
    @ResponseBody
    @ApiOperation(value="手机号是否已注册",notes="手机号是否已注册!")
    @RequestMapping(value = "/existsMobile", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号")
    })
    public Object isExistMobile(
            HttpServletRequest request,
            @RequestParam(value = "mobile",defaultValue = "") String mobile){

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        UserCustomerInfo item = userCustomerInfoService.getUserInfoByMobile(mobile);

        if(null != item){
            return  new ApiResult( ApiResultConstant.APP_MOBILE_EXISTS );
        }

        return new ApiResult( ApiResultConstant.SUCCESS);
    }


    /**
     *  获取注册短信验证码
     */
    @ResponseBody
    @ApiOperation(value="获取注册短信验证码",notes="注册短信码有效期5分钟!")
    @RequestMapping(value = "/getRegisterCode", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号")
    })
    public Object getRegisterCode(
            HttpServletRequest request,
            @RequestParam(value = "mobile",defaultValue = "") String mobile){

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        UserVerifyJnl item = userVerifyJnlService.getRegisterCode( mobile );

        if(null != item){
            return  new ApiResult( ApiResultConstant.SUCCESS );
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }

    /**
     *  获取密码修改短信验证码
     */
    @ResponseBody
    @ApiOperation(value="获取密码修改短信验证码",notes="重置密码，修改密码时获取的短信验证码需要调用此接口!")
    @RequestMapping(value = "/getPasswordCode", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号")
    })
    public Object getPasswordCode(
            HttpServletRequest request,
            @RequestParam(value = "mobile",defaultValue = "") String mobile){

        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        UserVerifyJnl item = userVerifyJnlService.getPasswordCode(mobile);

        if(null != item){
            return  new ApiResult( ApiResultConstant.SUCCESS );
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }


    /**
     *  获取信息变更短信验证码
     */
    @ResponseBody
    @ApiOperation(value="获取信息变更短信验证码",notes="重要信息变更时获取的短信验证码需要调用此接口!")
    @RequestMapping(value = "/getInfoUpdateCode", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号")
    })
    public Object getInfoUpdateCode(
            HttpServletRequest request,
            @RequestParam(value = "mobile",defaultValue = "") String mobile){
        //验证手机号的正确性
        if(StringUtils.isEmpty( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        if(!IDCardUtil.mobile( mobile )){
            return new ApiResult( ApiResultConstant.APP_MOBILE_ERROR);
        }

        UserVerifyJnl item = userVerifyJnlService.getInfoUpdateCode(mobile);

        if(null != item){
            return  new ApiResult( ApiResultConstant.SUCCESS );
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }

    /**
     *  限行信息
     */
    @ResponseBody
    @ApiOperation(value="限行信息",notes="根据城市代码编号或者名称查询当地的限行信息!")
    @RequestMapping(value = "/getXianxing", method = RequestMethod.POST)
    @ApiImplicitParams( value = {
            @ApiImplicitParam(paramType = "query", name = "city", dataType = "String", required = true, value = "城市代码编号或者名称")
    })
    public Object getXianxing(
            HttpServletRequest request,
            @RequestParam(value = "city",defaultValue = "") String city){

        //验证手机号的正确性
        if(StringUtils.isEmpty( city )){
            return new ApiResult( ApiResultConstant.FAILED);
        }

        ItcsCityInfo cityInfo = itcsCityInfoService.getIsXianxingCity( city );

        if(null != cityInfo){
            ItcsCityLimitInfo xianxing = itcsCityLimitInfoService.getXianxingCity( cityInfo.getCity() );

            if(null != xianxing){
                return  new ApiResult( ApiResultConstant.SUCCESS,xianxing);
            }
        }

        return new ApiResult( ApiResultConstant.FAILED);
    }

}